package org.sanqi.demo.controller;

import org.sanqi.demo.entity.User;
import org.sanqi.demo.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: JenSen
 * @Date: 2024/5/22 14:33
 * @Description: UserController
 */
@Controller
@RestController
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/save")
    public Object save(String userName){
        User user = new User();
        user.setSno("s011");
        user.setSname(userName);
        user.setSage("33");
        user.setSsex("男");
        return userService.save(user);
    }

    @GetMapping("/userList")
    public List<User> userList(){
        return userService.getUserList();
    }
    @GetMapping("/logout")
    public void logout(){
        userService.deleteAll();
    }

    @GetMapping("/getCache")
    public void getCache(){
        userService.getConcurrentHashMapCache();
    }

    @GetMapping("/update")
    public void upDate(String name,String age,String sex){
        User user = new User();
        user.setSno("s001");
        user.setSname(name);
        user.setSage(age);
        user.setSsex(sex);
        userService.updateUser(user);
    }
}
